<template>
	<div class="todayActivity">
		<group class="todayActivityGroup">
			<div style="margin-top: 10px; margin-bottom: 10px">
				<span class="blockTitle">{{title}}</span>
			</div>
		</group>

		<div v-if="items.length == 0" class="noEvents">
			<img slot="icon" src="@/assets/svg/noEvents.svg">
			<div style="font-size: 12px; padding: 5px">看起来你今天没有什么工作了。</div>
		</div>

		<cell class="cellHomeAct"
		      v-for="item in items"
		      :title="item.time"
		      value-align="left"
		      @click.native="jumpTo(item.activity_id)">
			<span style="float: left; padding: 5px; background-color: #ff5a00; color: white">{{item.activity_type}}</span>
			<span style="float: left; padding: 5px;">{{item.name}}</span>
			<span v-if="item.status == 2" style="float: right;padding: 5px;background-color: #a2cf45; color: white">已完成</span>
			<span v-else-if="item.status == 1" style="float: right;padding: 5px;background-color: rgb(255,210,0); color: white">已确定</span>
			<span v-else-if="item.status == 0" style="float: right;padding: 5px;background-color: rgb(67, 171, 227); color: white">未确定</span>
			<span v-else-if="item.status == 3" style="float: right;padding: 5px;background-color: darkgray; color: white">已丢弃</span>
		</cell>

		<x-button class="calendarBtn" @click.native="viewCalendar">查看日历</x-button>

	</div>
</template>

<script>
	import NetWorking from '../../../../utils/networking'
	import dateutils from '../../../../utils/date'
	import {Group, Cell, XButton} from 'vux'
	export default {
		name: "today-activity",
		components: {
			Group,
			Cell,
			XButton
		},
		data() {
			return {
				title: '今日事件',
				items: []
			}
		},
		created: function () {
			let _this = this
			let user = this.$store.state.user.userModel.sysUser
			let date = dateutils.getDate(new Date())
			NetWorking.doGet(
				'ai/getUserActListByDateWithRoleAndUser',
				null,
				{
					params: {
						date: date,
						role: 'consultant',
						username: user.username,
						actType: 'S_LOV_SALES'
					}
				}
			).then(
				response => {
					let rs = response.data
					if(rs.error_code == 0){
						_this.items = rs.user_act_date_list
					}else{
						alert(rs.error_message)
					}
				}
			)
		},
		methods: {
			jumpTo: function (id) {
				//组件间传递参数
				this.$router.push({ name: "activityDetails", params: { id: id }})
			},

			viewCalendar: function () {
				this.$router.push({ name: "calendar", params: { rolePlay: 'consultant', actType: 'S_LOV_SALES' }})
			}
		}

	}
</script>

<style>
	.todayActivity {
		margin-bottom: 10px;
	}

	.noEvents {
		padding: 10px;
		background-color: white;
		text-align: center;
	}

	.cellHomeAct{
		background-color: white;
		padding: 0px 15px !important;
	}

	.cellHomeAct > .weui-cell__ft{
		font-size: 12px;
		padding-left: 10px;
	}

	.cellHomeAct > .vux-cell-bd{
		font-size: 12px;
	}

	.calendarBtn {
		background-color: white !important;
		border-radius: 0px !important;
		font-size: 14px !important;
		color: #528dd9 !important;
	}
</style>